<?php 

	//Connect to the database.
	$con = mysqli_connect ("db.cse.unt.edu", 'acmrepo', 'B8cpU6GBx9qJJmN8', 'acmrepo');

	if (mysqli_connect_errno()) {
		echo "Failed to connect to MySQL: " . mysqli_connect_error();
	}
	
	if (is_numeric($_GET['id'])) {
		$query = "SELECT * FROM files WHERE file_id = '" . $_GET['id'] . "'";
		if ($result = mysqli_query($con, $query)) {
			$row = mysqli_fetch_array($result);
			$size = $row['file_size'];
			$name = $row['file_name'];
			$type = $row['file_type'];
			$content = $row['file_contents'];
			
			header("Content-length: " .$size."");
			header("Content-type: " .$type."");
			header("Content-Disposition: attachment; filename='" .$name."'");
			echo $content;
		}
		else echo "Error";
	}

?>